package moltencore.network.protocol;

import spark.network.protocol.Base;
import spark.network.Util;

public class StartGame extends Base {
	public static final short TYPE = 0x42;
	private static final byte[] TYPE_BYTES = Util.makeBytes(TYPE);

	private long hostIdentification;
	private static final int HOST_IDENTIFICATION_OFFSET = Base.SIZE;
	private static final int HOST_IDENTIFICATION_LENGTH = Long.SIZE / 8;

	private static final int SIZE =
			Base.SIZE +
	        HOST_IDENTIFICATION_LENGTH;

	public StartGame() {
		super(true, TYPE_BYTES);
	}

	public long getHostIdentification() {
		return hostIdentification;
	}

	public void setHostIdentification(long hostIdentification) {
		this.hostIdentification = hostIdentification;
	}

	@Override
	public int getSize() {
		return SIZE;
	}

	@Override
	public void fill(byte[] buffer) {
		super.fill(buffer);
		hostIdentification = Util.makeLong(buffer, HOST_IDENTIFICATION_OFFSET);
	}

	@Override
	public void getBytes(byte[] buffer) {
		super.getBytes(buffer);
		Util.arraycopy(Util.makeBytes(hostIdentification), 0, buffer, HOST_IDENTIFICATION_OFFSET);
	}

	public static StartGame create(byte[] buffer, long receiveTime) {
		StartGame packet = new StartGame();
		packet.fill(buffer);
		packet.setTimeStampReceive(receiveTime);
		return packet;
	}
}
